#include <shell/simple_shell.h>
#include <utils/scope_timer.h>
#include <buzzer/buzzer.h>


int blink(int freq, long time)
{
  long t = 0;
  while (t < time)
  {
    digitalWrite(13, HIGH);
    delay(freq);
    digitalWrite(13, LOW);
    delay(freq);
    t += freq * 2;
  }

  return 0;
}

int toto(int freq, long time)
{
  return blink(freq, time);
}

int main(void)
{
  init();

  pinMode(13, OUTPUT);

  buzzer::buzzer bz(6);

  auto buzz = [&bz] (int tone, int duration)
  { bz.play_tone(tone, duration); return 0; };

  shell::simple_shell sh(shell::BR115200);

  sh.add_function("blink", utils::make_function(blink));
  sh.add_function("buzz", utils::function<int(int,int)>(buzz));

  while (true)
  {
    utils::scope_timer timer(100);
    sh.update();
  }

  return 0;
}
